// pages/my/complaint/complaint.js
Page({
  data: {
    id: "",
    historyId: "",
    reviewStatus: "",
    message: "",
    fileList: [],
    imgIds: [],
    dialog_show: false
  },
  onLoad: function (options) {
    this.setData({
      id: options.id,
      historyId: options.historyId,
      reviewStatus: options.reviewStatus
    });
  },
  upload(e) {
    getApp().globalData.util.imgsUpload(this, e, this.data.fileList, this.data.imgIds);
  },
  delete(e) {
    let i = e.detail.index;
    let fileList = this.data.fileList;
    let imgIds = this.data.imgIds;
    fileList.splice(i, 1);
    imgIds.splice(i, 1);
    this.setData({
      fileList: fileList,
      imgIds: imgIds
    });
  },
  submit() {
    if (!this.data.message) {
      getApp().globalData.vant.toast("请填写申诉内容");
    } else if (this.data.imgIds.length == 0) {
      getApp().globalData.vant.toast("请上传图片");
    } else {
      getApp().globalData.http.evidence({
        id: this.data.id,
        historyId: this.data.historyId,
        reviewStatus: this.data.reviewStatus,
        secondEvidenceContent: this.data.message,
        secondEvidenceImgIds: this.data.imgIds.join(",")
      }).then(res => {
        this.setData({
          dialog_show: true
        });
      }).catch(e => {
        getApp().globalData.vant.toast(e.msg);
      });
    }
  },
  successClick() {
    wx.navigateBack({
      delta: 2,
      success: function (e) {
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.getData();
      }
    });
  },
})